package com.loopy.fruns.web;

import com.loopy.fruns.entity.Admin;
import com.loopy.fruns.service.AdminService;
import com.loopy.fruns.service.impl.AdminServiceImpl;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;

public class AdminServlet extends BasicServlet {
    private AdminService adminService=new AdminServiceImpl();
//    @Override
//    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        doPost(request, response);
//    }


    protected void login(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("user-name");
        String password = request.getParameter("user-password");
        Admin admin = adminService.login(new Admin(null, username, password));
        if(admin==null){
            request.setAttribute("username",username);
            request.setAttribute("msg","用户名或密码错误");
            request.getRequestDispatcher("/views/manage/manage_login.jsp").forward(request,response);
        }else{
            request.getRequestDispatcher("/views/manage/manage_menu.jsp").forward(request,response);
        }
//        System.out.println("AdminServlet被调用");

    }

//        @Override
//    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
//        String username = request.getParameter("user-name");
//        String password = request.getParameter("user-password");
//        Admin admin = adminService.login(new Admin(null, username, password));
//        if(admin==null){
//            request.setAttribute("username",username);
//            request.setAttribute("msg","用户名或密码错误");
//            request.getRequestDispatcher("/views/admin/manage_login.jsp").forward(request,response);
//        }else{
//            request.getRequestDispatcher("/views/admin/manage_menu.jsp").forward(request,response);
//        }
////        System.out.println("AdminServlet被调用");
//
//    }
}
